﻿using UnityEngine;
using iTManager;
public interface IButtonController  {
	void Action();
}
public class ButtonOption:IButtonController{
	private GameManager manager;
	private Vector3 velocity;
	private Vector3 old_position;
	private GameObject[] buttons;
	public ButtonOption(GameObject[] buttons){
		manager=GameManager.getInstance();
		this.buttons=buttons;
		manager.BarShow=false;
		setActiveButton(false);
	}
	private void setActiveButton(bool active){
		foreach (GameObject button in buttons) {
			button.SetActive(active);	
		}
		if(!manager.IsShow) return;
		if(manager.Sound){
			buttons[2].SetActive(manager.Sound);
			buttons[3].SetActive(!manager.Sound);
		}else{
			buttons[3].SetActive(!manager.Sound);
			buttons[2].SetActive(manager.Sound);
			buttons[3].transform.position=buttons[2].transform.position;
		}
		if(manager.Music){
			buttons[4].SetActive(manager.Music);
			buttons[5].SetActive(!manager.Music);
		}else{
			buttons[5].SetActive(!manager.Music);
			buttons[4].SetActive(manager.Music);
			buttons[5].transform.position=buttons[4].transform.position;
		}
	}
	public void Action(){
		manager.IsShow=!manager.IsShow;
		if(!manager.IsShow){
			Show();
		}
	}
	public void Show(){
		setActiveButton(manager.IsShow);
	}
}

public class MusicSound : IButtonController
{
	private GameObject[] musics;
	private bool active;
	public MusicSound(GameObject[] musics,bool active){
		this.musics=musics;
		this.active=active;
	}
	public void Action(){
		if(active){
			SetActiveButtons(active);           
		}else{
			SetActiveButtons(!active);
			musics[1].transform.position=musics[0].transform.position;
		}
	}
	private void SetActiveButtons(bool active){
		musics[1].SetActive(active);
		musics[1].SetActive(!active);
	}
}


public class Play : IButtonController
{
	private AsyncOperation asyn;
	public int scence;
	public Play(int scence){
		this.scence=scence;
	}
	public void Action(){
		Application.LoadLevel(scence);
	}
}

public class Facebook : IButtonController
{
	public void Action(){
		Debug.Log("Facebook");
	}
}

public class OpenDialog : IButtonController
{
	public GameObject[] objects;
	private GameManager manager;
    
	public  OpenDialog(GameObject[] objects){
		this.objects=objects;
		manager=GameManager.getInstance();
	}
    public OpenDialog() {  }

	public void Action(){
     	manager.IsShow=false;
		objects[1].SetActive(true);
		objects[1].MoveTo(new MoveTo(){
			position_Vector3 = new Vector3(0.160647f, -0.1530831f, 0),
			time = 1,
			easetype = iTweenBase.EaseType.linear
		})
			.OnStart(() => { objects[0].SetActive(true); })
			.Start();
        
	}
    
}

public class CloseDialog : IButtonController
{
	private GameObject[] objects;
	private Vector3 old_position;
	public CloseDialog(GameObject[] objects,Vector3 old_position){
		this.objects=objects;
		this.old_position=old_position;
	}
	public void Action(){
		objects[1].transform.position =old_position;
		objects[0].SetActive(false);
		objects[1].SetActive(false);
	}
}










